﻿using CPPEI.ETL.DataServiceInterface;
using CPPEI.WebApi;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

using ENT = CPPEI.ETL.Domain.Entities;
using MOD = CPPEI.ETL.Domain.Models;
using SER = CPPEI.ETL.Domain.Services;

namespace CPPEI.ETL.WebApi
{
    [CPPEI.WebApi.AuthPostAction("ETL", "CreateDimItem", "1.0")]
    public class CreateDimItemAction : BaseAction<CreateDimItemParams, CreateDimItemResult>
    {
        protected override ActionResult<CreateDimItemResult> OnExecute(ActionContext context, 
            SysParameters sysParameters,
            CreateDimItemParams opParams)
        {
            SER.DimService service = new SER.DimService();
            ServiceResult<ENT.EDimItem> serResult = service.CreateDimItem(context.UserId, opParams.DimId, opParams.Code, opParams.Name, opParams.EffectiveDate, opParams.ExpiryDate);
            if(serResult.IsSuccess)
            {
                CreateDimItemResult result = new CreateDimItemResult();
                result.Id = serResult.Data.Id;
                return new ActionResult<CreateDimItemResult>(result);
            }
            else
            {
                return new ActionResult<CreateDimItemResult>(serResult.IsSuccess, serResult.ErrorCode, serResult.Message, null);
            }
        }
    }

    public class CreateDimItemParams
    {
        [Parameter]
        /// <summary>
        /// 生效日期
        /// </summary>
        public DateTime EffectiveDate { get; set; }

        [Parameter]
        /// <summary>
        /// 失效日期
        /// </summary>
        public DateTime ExpiryDate { get; set; }

        [Parameter]
        public Guid DimId { get; set; }

        [Parameter]
        public string Name { get; set; }

        [Parameter]
        public string Code { get; set; }
    }

    public class CreateDimItemResult
    {
        public Guid Id { get; set; }
    }
}
